package com.mew.lobby.handler.user;

import com.mew.common.entity.user.User;
import com.mew.common.exception.ResponseCode;
import com.mew.common.rest.IntMessage;
import com.mew.common.rest.bo.MewSession;
import com.mew.lobby.annotation.LobbyHandler;
import com.mew.lobby.net.LobbyHandlerMapCmdType;
import com.mew.lobby.net.MewHandler;
import com.mew.lobby.provide.UserFeignService;
import com.zebra.remoting.protocol.ZebraCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**修改头像
 * @author dylin
 * @create 2021/1/26 0026
 */
@Service
@Slf4j
@LobbyHandler(LobbyHandlerMapCmdType.Head)
public class HeadHandler implements MewHandler<IntMessage> {
    @Autowired
    private UserFeignService userFeignService;

    @Override
    public void handle(ZebraCommand<IntMessage> zebraCommand, MewSession session) {
        long userId = zebraCommand.getUserId();
        int headPath = zebraCommand.getRequest().getI();
        int code = userFeignService.updateUser(
                User
                        .builder()
                        .id(userId)
                        .headPath(headPath)
                        .build()
        );
        if(code== ResponseCode.Success.code()){
            zebraCommand.sendMessage(IntMessage.builder().i(headPath).build());
            return;
        }
        zebraCommand.sendFailureCode(code);
    }
}
